<!--
 * @Author: daidai
 * @Date: 2022-02-20 16:16:42
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-10-25 09:18:22
 * @FilePath: \web-pc\src\pages\big-screen\view\indexs\left-center.vue
-->
<template>
  <Echart id="leftCenter" v-if="pageflag" :options="options" isClick class="left_center_inner" ref="charts"
    height="180px" @chartClick="chartClick" style="margin-top: -10px" />
  <Reacquire v-else @onclick="getData" style="line-height: 200px">
    重新获取
  </Reacquire>
</template>

<script>
import { currentPOST } from 'api/modules';
import { colorsA, colorsB, legend, xAxis, yAxis } from '@/config/EChartVar';
import { graphic } from 'echarts';

export default {
  data() {
    return {
      options: {},
      countUserNumData: {
        axisData: ['2021', '2022', '2023', '2024', '2025'],
        seriesData0: [164782, 171084, 177264, 183763, 22587],
        seriesData1: [39, 42, 58, 91, 82],
      },
      pageflag: true,
      timer: null,
    };
  },
  created() {
    this.getData();
  },
  mounted() { },
  beforeDestroy() {
    this.clearData();
  },
  methods: {
    clearData() {
      if (this.timer) {
        clearInterval(this.timer);
        this.timer = null;
      }
    },
    getData() {
      this.pageflag = true;

      this.$nextTick(() => {
        this.init(this.countUserNumData);
      });
    },
    //轮询
    switper() {
      if (this.timer) {
        return;
      }
      let looper = (a) => {
        this.getData();
      };
      this.timer = setInterval(
        looper,
        2000 // this.$store.state.setting.echartsAutoTime // staticAutoTime
      );
      let myChart = this.$refs.charts.chart;
      myChart.on('mouseover', (params) => {
        this.clearData();
      });
      myChart.on('mouseout', (params) => {
        this.timer = setInterval(
          looper,
          2000 // this.$store.state.setting.echartsAutoTime // staticAutoTime
        );
      });
    },
    init(currentData) {
      // let axisData = ["2021年", "2022年", "2023年", "2024年"];
      let axisData = currentData.axisData;
      let seriesData = [
        [...currentData.seriesData0],
        // [...currentData.seriesData1],
      ];

      const options = {
        grid: {
          top: '15%',
          left: '4%',
          right: '8%',
          bottom: '0%',
          containLabel: true,
        },
        legend: {
          show: true,
          top: '0%',
          right: '4%',
          icon: 'circle',
          itemWidth: 12,
          itemHeight: 12,
          // itemGap: 60,
          textStyle: legend.textStyle,
          data: ['万元'],
        },
        xAxis: {
          type: 'category',
          data: axisData,
          // boundaryGap: false,
          boundaryGap: true,
          splitLine: {
            show: false,
          },
          axisTick: {
            show: false, // 不显示下切线
          },
          axisLabel: xAxis.axisLabel,
          axisLine: {
            lineStyle: {
              background: 'rgba(176, 215, 255, 0.4)',
            },
          },
        },
        yAxis: [
          {
            type: 'value',
            // max: 800,
            // min: 0,//
            // interval: 2000,
            axisLabel: yAxis.axisLabel,
            axisLine: {
              show: false,
              // interval: 1,
              lineStyle: {
                color: 'rgba(0,0,0,0.5)',
              },
            },
            splitLine: {
              show: true,
              // interval: 1,
              lineStyle: {
                color: ['rgba(176, 215, 255, 0.2)'],
                width: 1,
                type: 'dashed',
              },
            },
            // splitLine: {
            //   show: false,
            // },
            axisTick: {
              show: false,
            },
          },
        ],
        series: [],
      };
      const series = [
        {
          name: '万元',
          type: 'bar',
          smooth: true,
          showSymbol: false,
          symbol: 'circle',
          symbolSize: 6,
          barWidth: 30,
          data: seriesData[0],
          itemStyle: {
            normal: {
              // color: "#38FFBA",
              color: 'rgba(0,239,254,0.6)',
            },
          },
          // areaStyle: {
          //   color: colorsA[0],
          // },
          lineStyle: {
            normal: {
              width: 2,
            },
          },
          label: {
            show: false,
            position: 'top',
            formatter: (par) => {
              // return par.value + '万元';
              return par.value;
            },
            textStyle: { fontSize: 11, color: '#FFF' },
          },
          // markPoint: {
          //   symbol: 'circle',
          //   symbolSize: [14, 14], // 容器大小
          //   symbolOffset: ['0%', '0%'],
          //   data: [
          //     {
          //       name: '最大值',
          //       type: 'max',
          //       valueIndex: 1,
          //     },
          //   ],
          //   label: {
          //     show: false,
          //     position: 'top',
          //     fontSize: 12,
          //     color: '#FFF',
          //     formatter: (par) => {
          //       // return par.value + '万元';
          //       return par.value;
          //     },
          //   },
          // },
        },
      ];
      options.series = series;
      this.options = options;
    },
    chartClick(params) {
      console.log("🚀 ~ chartClick ~ params:", params)
      const idx = this.countUserNumData.seriesData0.findIndex(item => item === params.value)
      const name = this.countUserNumData.axisData[idx]
      // 这里处理你的点击逻辑
      this.$emit('chartClick', { ...params, name }, '', 'RightLeftTop');
      // this.$emit('chartClick', { ...params }, '', 'RightLeftTop');
    },
  },
};
</script>
<style lang="scss" scoped></style>
